﻿// =================================================================== 
// 项目说明
//====================================================================
// lsc @Copy Right 2019
// 文件： NetworkOrderRepository.cs
// 项目名称：斑马车务
// 创建时间：2019-01-23
// 负责人：lsc
// ===================================================================
using System;
using System.Text;
using System.Collections.Generic;
using CGT.Infrastructure.Entity;
using Dapper.Extensions;
using CGT.Infrastructure.Dto;
using Dapper;
using System.Data;
using System.Linq;

namespace CGT.Infrastructure.Repository
{
	/// <summary>
	///网办订单 仓储层
	/// </summary>	
	public class NetworkOrderRepository:BaseRepository<NetworkOrder>
	{		
    
        #region 构造

        public NetworkOrderRepository() : base(){}

        public NetworkOrderRepository(string connectionString) : base(connectionString){}

        public NetworkOrderRepository(DatabaseContext dbContext) : base(dbContext){}

        #endregion

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public List<NetworkOrderDto> GetList(GovNetworkOrderCondition condition)
        {
            List<NetworkOrderDto> list = new List<NetworkOrderDto>();
            var param = new DynamicParameters();
               param.Add("@OpUserId", condition.OpUserID, DbType.Int32);
               param.Add("@OrderID", condition.OrderID, DbType.Int64);
               param.Add("@ProvinceId", condition.ProvinceId, DbType.Int32);
               param.Add("@CityId", condition.CityId, DbType.Int32);
               param.Add("@MasterBizTypeId", condition.MasterBizTypeId, DbType.Int32);
               param.Add("@BizTypeId", condition.BizTypeId, DbType.Int32);
               param.Add("@StartDateTime", condition.StartDateTime, DbType.String);
               param.Add("@EndDateTime", condition.EndDateTime, DbType.String);
               param.Add("@pageIndex", condition.PageIndex, DbType.Int32);
               param.Add("@pageSize", condition.PageSize, DbType.Int32);
               param.Add("@OutCount", 0, DbType.Int32, ParameterDirection.Output);
            list = dbContext.Connection.Query<NetworkOrderDto>("p_GovNetworkOrder_search", param, null, true, null, CommandType.StoredProcedure).ToList();//res2.Count = 80
            condition.OutCount = param.Get<int>("@OutCount");
            return list;
        }

        /// <summary>
        /// 获取订单详细信息
        /// </summary>
        /// <param name="orderId"></param>
        /// <returns></returns>
        public NetworkOrderDetailDto GetOrderInfo(long orderId)
        {
            var param = new DynamicParameters();
            param.Add("@OrderID", orderId, DbType.Int64);
            NetworkOrderDetailDto obj = dbContext.Connection.Query<NetworkOrderDetailDto>("p_NetworkOrderInfo_search", param, null, true, null, CommandType.StoredProcedure).First();
            return obj;
        }
    }
}